package com.study.controller;

import com.alibaba.fastjson.JSON;
import com.study.entity.BusReceiverEntity;
import com.study.service.BusReceiverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MyController {

    @Autowired
    BusReceiverService busReceiverService;

    @RequestMapping("findName/{name}")
    public String findByName(@PathVariable String name){
        BusReceiverEntity busReceiverEntity = busReceiverService.findByName(name);
        return JSON.toJSONString(busReceiverEntity);
    }

    @RequestMapping("findAll")
    public String findAll() {
        return JSON.toJSONString(busReceiverService.findAll());
    }


    @RequestMapping("findByNameMatch/{name}")
    public String findByNameMatch(@PathVariable String name) {
        return JSON.toJSONString(busReceiverService.findByNameMatch(name));
    }

    @RequestMapping("findById/{id}")
    public String findById(@PathVariable Long id) {
        return JSON.toJSONString(busReceiverService.findById(id));
    }
}
